package com.hj.surface;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Point;

public class Smile {
	private Bitmap bm;
	private Point sp;// 笑脸的起点
	private Point ep;// 笑脸的终点
	private float space;

	private int px = 0;
	private int py = 0;

	public Smile(Bitmap bm, Point sp, Point ep, float space) {
		super();
		this.bm = bm;
		this.sp = sp;
		this.ep = ep;
		this.space = space;

		px = sp.x;
		py = sp.y;
	}

	public void draw(Canvas canvas) {
		canvas.drawBitmap(bm, px, py, null);
		tick();
		if(GameData.screenX < px || px < -bm.getWidth() || py < - bm.getHeight() || py > GameData.screenY){  
            isDestroy = true;  
        }  
	}
	/** 
     * 用于改变笑脸的位置 
     */ 
	private void tick() {
		if (ep.x > sp.x) {
			px += (ep.x - sp.x) * space;
		} else if (sp.x > ep.x) {
			px -= (sp.x - ep.x) * space;
		}
		if (ep.y > sp.y) {
			py += (ep.y - sp.y) * space;
		} else {
			py -= (sp.y - ep.y) * space;
		}
	}

	private boolean isDestroy = false;

	public boolean isDestroy() {
		return isDestroy;
	}
}
